#!/usr/bin/perl -w

sub get_working_ssh_ip {
my $timeout=shift;
my @ips=@_;
my $cip;
my $rip;

	for $cip (@ips) {
		eval {
			local $SIG{ALRM}=sub { die "TIMEOUT" };
			alarm(2);
			`ssh $cip ls 2>&1`;
			alarm(0);
		};
		
		if($@ && $@ =~ /TIMEOUT/) {
			next;
		}
		$rip=$cip; last;
	}
	return($rip) if defined($rip);
	return undef;
}

$cc=get_working_ssh_ip(3,"192.168.0.29","192.168.0.30","192.168.0.31");

print "cc=$cc\n" if defined($cc);
	
 
